<?php
/**
 * 物件一覧 共通クラス<br />
 *
 * @package apamanshop
 * @author SS永田
 * @copyright コピーライト(要確認)
 */
class Rstobi_Model_Common extends Apm_Model_Base
{

	/* 区切り文字取得 */
	/*
	/* 第1引数を判定し、0の場合は空を返却
	/* それ以外は、第2引数で渡された文字を返却
	/*
	/* @access public
	/* $param  number
	/* $param  string
	/* $return string
	/*
	 */
	public function getPause($index,$Pausen)
	{
		$retValue = '';

		if($index <> 0)
		{
			$retValue = $Pausen;
		}

		return $retValue;
	}

	/**
	 * OEM用From句・Where句を取得
	 *
	 * @access public
	 * $param array
	 * @param array ※参照渡し
	 * $return array
	 */
	public function getOemFromWhere($params ,&$db_params)
	{
		$strOemTenpoCd = '';
		$strOemKigyoCd = '';
		$strFrom  = '';
		$strWhere = '';
		$arySql['from']  = '';
		$arySql['where'] = '';

		// インスタンス生成
    	$loader = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Search',
			'basePath' => APPLICATION_PATH . '/modules/search',
		));
		$this->_model_search_common  = new Search_Model_Common();  //共通クラス（検索導線）

		// 物件一覧からの遷移かを判定
		if($params['IsbukenList'] == 1)
		{
			$db_params['strOemTenpoCd'] = $params['OemCd'];

			// OEMコードが8桁（店舗）
			If(strlen($params['OemCd']) == 8)
			{
				$strWhere  = ' AND T03.T03_TENPO_CD = M05.M05_TENPO_CD';
				$strWhere .= ' AND M05.M05_TENPO_CD = :strOemTenpoCd ';

				$strFrom   = ' ,M05TENPO_INFO M05';
			}
			// OEMコードが4桁（法人）
			else if(strlen($params['OemCd']) == 4)
			{
				$strWhere  = ' AND T03.T03_TENPO_CD = M05.M05_TENPO_CD';
				$strWhere .= ' AND M05.M05_HOUZIN_CD = :strOemTenpoCd ';

				$strFrom   = ' ,M05TENPO_INFO M05';
			}
			else
			{
				echo 'OEMコードが不正です。';
				exit;

			}
		}
		else
		{
			// OEMならFrom句、Where句を作成する
			if($this->isOem($params))
			{
				// OEMコードを配列に詰め直す
				$aryOemCd = explode(",",$params['OemCd']);

				for($i=0; $i < count($aryOemCd); $i++)
				{
					$strComma = '';

					// OEMコードが8桁（店舗）
					If(strlen($aryOemCd[$i]) == 8)
					{
						if(strlen($strOemTenpoCd) > 0)
						{
							$strComma = ',';
						}

						$db_params['strOemTenpoCd_'.$i] = $aryOemCd[$i];

						$strOemTenpoCd .= $strComma.' :strOemTenpoCd_'.$i.' ';
					}
					// OEMコードが4桁（法人）
					else if(strlen($aryOemCd[$i]) == 4)
					{
						if(strlen($strOemKigyoCd) > 0)
						{
							$strComma = ',';
						}

						$db_params['strOemKigyoCd_'.$i] = $aryOemCd[$i];

						$strOemKigyoCd .= $strComma.' :strOemKigyoCd_'.$i.' ';
					}
					else
					{
						echo 'OEMコードが不正です。';
						exit;
					}
				}

				$strWhere  = ' AND T03.T03_TENPO_CD = M05.M05_TENPO_CD';
				// 店舗
				if(strlen($strOemTenpoCd) > 0)
				{
					$strWhere .= ' AND M05.M05_TENPO_CD in ( '.$strOemTenpoCd.' )';
					$strWhere .= ' AND (M05.M05_OEM = 2 OR M05.M05_OEM = 3)';
				}

				// 企業
				if(strlen($strOemKigyoCd) > 0)
				{
					$strWhere .= ' AND M05.M05_HOUZIN_CD in ( '.$strOemKigyoCd.' )';
					$strWhere .= ' AND (M05.M05_OEM = 1 OR M05.M05_OEM = 3)';
				}

				$strFrom   = ' ,M05TENPO_INFO M05';
			}
		}

		$arySql['from']  = $strFrom;
		$arySql['where'] = $strWhere;

		return $arySql;
	}
	/**
	 * 基本条件選択のWhere句を取得
	 *
	 * @access public
	 */
	public function getKihonWhere($params ,&$db_params, $iconFlag=true)
	{
		/***********************************************/
		/* フリーワード専用の基本条件は以下を参照      */
		/*「/modules/rstobi/models/FreewordSearch.php」*/
		/***********************************************/

		$where = "";

		// 公開店舗限定
		$where .= " AND EXISTS (SELECT 1 FROM M05TENPO_INFO M05 WHERE T03.T03_TENPO_CD = M05.M05_TENPO_CD AND M05.M05_KOUKAI_FLAG = 1) ";

		//++++++++++++++++++++++++++++++++++++++++
		//賃料
		// tinryo1        : 下限
		// tinryo2        : 上限
		// tinryo_jouken2 : 管理費・共益費込み
		// tyusyajyo_komi : 駐車場込み
		// meyasu_tinryo  : めやす賃料
		// freerent       : フリーレント
		// shikireizero   : 敷金・礼金０
		// shikikin_nashi : 敷金なし
		// reikin_nashi   : 礼金なし
		// heyawari       : 部屋割
		// shataku_koujyo : 仲介手数料（法人サイトのみ）
		// syokihiyo      : 初期費用
		//++++++++++++++++++++++++++++++++++++++++

		//めやす賃料
		if (!empty($params['meyasu_tinryo']) && $params['meyasu_tinryo'] == 'meyasu')
		{
//			if($this->isOem($params)){
//				$work_yachin = 'T03.T03_TEN_MEYASU_CHINRYO';
//			}
//			else
//			{
//				$work_yachin = 'T03.T03_MEYASU_CHINRYO';
//			}

			// 2010/12/15 集約表示戻し対応
			$work_yachin = ' (CASE WHEN NVL(T03_TEN_MEYASU_CHINRYO,0) != 0 THEN T03_TEN_MEYASU_CHINRYO ELSE DECODE(NVL(T03_MEYASU_CHINRYO,0),0,9999999,T03_MEYASU_CHINRYO) END) ';

		}
		// 通常賃料
		else
		{
			$work_yachin = " T03.T03_YACHIN + NVL(T03.T03_YACHIN_TAX,0)";

			//管理費・共益費込み
			if (!empty($params['tinryo_jouken2']) && $params['tinryo_jouken2'] == "on")
			{
				$work_yachin .= " + NVL(T03.T03_KANRIHI, 0) + NVL(T03.T03_KANRIHI_TAX, 0) + NVL(T03.T03_KYOUEKIHI, 0) + NVL(T03.T03_KYOUEKIHI_TAX, 0)";
			}
			//駐車場込み
			if (!empty($params['tyusyajyo_komi']) && $params['tyusyajyo_komi'] == "on")
			{
				$work_yachin .= " + NVL(T03.T03_CHUUSHARYOU, 0) + NVL(T03.T03_CHUUSHARYOU_TAX, 0)";
			}
		}

		// 賃料の下限なし・上限あり
		if ( ( (isset($params['tinryo1']) && $params['tinryo1'] == "0") || !isset($params['tinryo1']) )
				&& isset($params['tinryo2']) && $params['tinryo2'] <> "9999999")
		{
			$db_params['strTinryo2'] = $params['tinryo2'];
			$where .= " AND ( " . $work_yachin . " <= :strTinryo2 ) ";
		}
		//賃料の下限あり・上限なし
		elseif (isset($params['tinryo1']) && $params['tinryo1'] <> "0" && $params['tinryo1'] <> "" &&
				( ((isset($params['tinryo2']) && $params['tinryo2'] == "9999999"))
				  || !isset($params['tinryo2'])
				  || $params['tinryo2'] =="" )
				)
		{
			$db_params['strTinryo1'] = $params['tinryo1'];
			$where .= " AND ( " . $work_yachin . " >= :strTinryo1 ) ";
		}
		//賃料の下限あり・上限あり
		elseif (isset($params['tinryo1']) && $params['tinryo1'] <> "0" && $params['tinryo1'] <> ""
				&& isset($params['tinryo2']) && $params['tinryo2'] <> "9999999")
		{
			$db_params['strTinryo1'] = $params['tinryo1'];
			$db_params['strTinryo2'] = $params['tinryo2'];

			$where .= " AND ( " . $work_yachin . " BETWEEN :strTinryo1 AND :strTinryo2 ) " ;
		}

		////////////////////////////////////

		//フリーレント
		if (!empty($params['freerent']) && $params['freerent'] == "on")
		{
//			if($this->isOem($params)){
//				$where .= " AND T03.T03_TEN_FREERENT_FLAG = 1 ";
//			}
//			else
//			{
//				$where .= " AND T03.T03_FREERENT_FLAG = 1 ";
//			}

			// 2010/12/15 集約表示戻し対応
			$where .= " AND (CASE WHEN NVL(T03.T03_TEN_FREERENT_FLAG,0) = 1 THEN T03.T03_TEN_FREERENT_FLAG ELSE T03.T03_FREERENT_FLAG END) = 1 ";
		}

		//部屋割
		if (!empty($params['heyawari']) && $params['heyawari'] == "on")
		{
//			if($this->isOem($params)){
//				$where .= " AND T03.T03_TEN_HEYAWARI_FLAG = 1 ";
//			}
//			else
//			{
//				$where .= " AND T03.T03_HEYAWARI_FLAG = 1 ";
//			}

			// 2010/12/15 集約表示戻し対応
			$where .= " AND (CASE WHEN NVL(T03.T03_TEN_HEYAWARI_FLAG,0) = 1 THEN T03.T03_TEN_HEYAWARI_FLAG ELSE T03.T03_HEYAWARI_FLAG END) = 1 ";
		}

		//敷金礼金０
		// UPDATE Start 2011/06/15 初期費用からダブル０独立対応 SS Ishii-n
		//if (!empty($params['shikireizero']) && $params['shikireizero'] == "on")
		if ((!empty($params['shikireizero']) && $params['shikireizero'] == "on") || (!empty($params['syokihiyo']) && $params['syokihiyo'] == "w0"))
		// UPDATE End   2011/06/15 初期費用からダブル０独立対応 SS Ishii-n
		{
			$where .= " AND T03.T03_KASHIDASHI_KUBUN = 1 ";
		}


		// 2011/01/25 保証金追加
		//敷金なし
		if (!empty($params['shikikin_nashi']) && $params['shikikin_nashi'] == "on")
		{
			$where .= " AND (     NVL(T03.T03_SHIKIKIN,0)  = 0 and NVL(T03.T03_SHIKIKIN_TSUKISUU,0)  = 0";
			$where .= "       and NVL(T03.T03_HOSHOUKIN,0) = 0 and NVL(T03.T03_HOSHOUKIN_TSUKISUU,0) = 0)";

		}
		// 2011/01/25 償却/敷引追加
		//礼金なし
		if (!empty($params['reikin_nashi']) && $params['reikin_nashi'] == "on")
		{
			$where .= " AND (     NVL(T03.T03_REIKIN,0)       = 0 and NVL(T03.T03_REIKIN_TSUKISUU,0)       = 0";
			$where .= "       and NVL(T03.T03_SHOUKYAKUKIN,0) = 0 and NVL(T03.T03_SHOUKYAKUKIN_TSUKISUU,0) = 0)";
		}

		//仲介手数料（法人サイトのみ）
		if (!empty($params['shataku_koujyo']) && $params['shataku_koujyo'] == "on")
		{
			// 社宅控除率を取得
			$db_params['strKoujyoritu'] = $this->getShatakuKoujyoritsu($params);

			$where .= " AND T03.T03_SHATAKU_TEKIYOU_FLAG = 1";
			$where .= " AND ((M05.M05_SHATAKU_KOUJYORITSU >= :strKoujyoritu ) OR (T03.T03_TORIHIKI_TAIYOU = 1) OR (T03.T03_TORIHIKI_TAIYOU = 9))";
		}

		// 仲介手数料無料


		//初期費用
		if (!empty($params['syokihiyo']))
		{
//			if($this->isOem($params)) {
//				$work_syokihiyo = 'T03.T03_TEN_SHOKI_HIYO';
//			} else {
//				$work_syokihiyo = 'T03.T03_SHOKI_HIYO';
//			}


			// 2010/12/15 集約表示戻し対応
			$work_syokihiyo = " (CASE WHEN T03_TEN_SHOKI_HIYO IS NOT NULL THEN T03_TEN_SHOKI_HIYO ELSE T03_SHOKI_HIYO END) ";

			// 2011/05/21 初期費用／ダブル０対応
			// 2011/06/14 初期費用からダブル０独立対応
			//0円
			if ($params['syokihiyo'] == '99') {
				$db_params['strSyokihiyo'] = '0';
				$where .= " AND (" . $work_syokihiyo . " = :strSyokihiyo) ";
				// DELETE Start 2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
				//$where .= "      OR T03.T03_KASHIDASHI_KUBUN = 1) ";
				// DELETE End   2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
			}
			//～3万円
			if ($params['syokihiyo'] == '3') {
				$db_params['strSyokihiyo'] = '30000';
				$where .= " AND (" . $work_syokihiyo . " <= :strSyokihiyo) ";
				// DELETE Start 2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
				//$where .= "      OR T03.T03_KASHIDASHI_KUBUN = 1) ";
				// DELETE End   2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
			}
			//～5万円
			if ($params['syokihiyo'] == '5') {
				$db_params['strSyokihiyo'] = '50000';
				$where .= " AND (" . $work_syokihiyo . " <= :strSyokihiyo) ";
				// DELETE Start 2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
				//$where .= "      OR T03.T03_KASHIDASHI_KUBUN = 1) ";
				// DELETE End   2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
			}
			//～7万円
			if ($params['syokihiyo'] == '7') {
				$db_params['strSyokihiyo'] = '70000';
				$where .= " AND (" . $work_syokihiyo . " <= :strSyokihiyo) ";
				// DELETE Start 2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
				//$where .= "      OR T03.T03_KASHIDASHI_KUBUN = 1) ";
				// DELETE End   2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
			}
			//～10万円
			if ($params['syokihiyo'] == '10') {
				$db_params['strSyokihiyo'] = '100000';
				$where .= " AND (" . $work_syokihiyo . " <= :strSyokihiyo) ";
				// DELETE Start 2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
				//$where .= "      OR T03.T03_KASHIDASHI_KUBUN = 1) ";
				// DELETE End   2011/06/14 初期費用からダブル０独立対応 SS Ishii-n
			}
		}

		//+++++++++++++++++++++++++++++++++++++++++++++
		//建物種別
		//
		// syubetu1 : 貸家アパート
		// syubetu2 : 貸家マンション
		// syubetu3 : 貸家一戸建て・借家
		// syubetu4 : 貸店舗・賃貸事務所
		// syubetu5 : 駐車場
		//+++++++++++++++++++++++++++++++++++++++++++++
		$aryTatemonoCd = array();

		if (!empty($params['syubetu1']) || !empty($params['syubetu2']) || !empty($params['syubetu3']) ||
			!empty($params['syubetu4']) || !empty($params['syubetu5']) )
		{

			//貸家アパート (アパート、ハイツ、コーポ)
			if (!empty($params['syubetu1']) && $params['syubetu1'] == "on")
			{
				array_push($aryTatemonoCd, Apm_Config_Search::TATEMONO_APART
										  ,Apm_Config_Search::TATEMONO_HEIGHTS
										  ,Apm_Config_Search::TATEMONO_CORP
										  ,Apm_Config_Search::TATEMONO_GESYUKU);
			}
			//貸家マンション (マンション)
			if (!empty($params['syubetu2']) && $params['syubetu2'] == "on")
			{
				array_push($aryTatemonoCd, Apm_Config_Search::TATEMONO_MANSION);
			}
			//貸家一戸建て・借家 (テラスハウス、タウンハウス、一戸建て、貸家、長屋)
			if (!empty($params['syubetu3']) && $params['syubetu3'] == "on")
			{
				array_push($aryTatemonoCd, Apm_Config_Search::TATEMONO_TERRACE
										  ,Apm_Config_Search::TATEMONO_TOWN
										  ,Apm_Config_Search::TATEMONO_IKKODATE
										  ,Apm_Config_Search::TATEMONO_KASIYA
										  ,Apm_Config_Search::TATEMONO_NAGAYA);
			}
			//貸店舗・賃貸事務所 (店舗、事務所、店舗・事務所、店舗付住宅、事業用建物、事業用土地、その他土地)
			if (!empty($params['syubetu4']) && $params['syubetu4'] == "on")
			{
				array_push($aryTatemonoCd, Apm_Config_Search::TATEMONO_TENPO
										  ,Apm_Config_Search::TATEMONO_JIMUSYO
										  ,Apm_Config_Search::TATEMONO_TENPO_JIMUSYO
										  ,Apm_Config_Search::TATEMONO_TENPO_JYUTAKU
										  ,Apm_Config_Search::TATEMONO_JIGYO_TATEMONO
										  ,Apm_Config_Search::TATEMONO_JIGYO_TOCHI
										  ,Apm_Config_Search::TATEMONO_SONOTA_TOCHI);
			}
			//駐車場 (駐車場)
			if (!empty($params['syubetu5']) && $params['syubetu5'] == "on")
			{
				array_push($aryTatemonoCd, Apm_Config_Search::TATEMONO_TYUSYAJYO);
			}
		}
		else
		{
			array_push($aryTatemonoCd, Apm_Config_Search::TATEMONO_APART
									  ,Apm_Config_Search::TATEMONO_HEIGHTS
									  ,Apm_Config_Search::TATEMONO_CORP
									  ,Apm_Config_Search::TATEMONO_GESYUKU
									  ,Apm_Config_Search::TATEMONO_MANSION
									  ,Apm_Config_Search::TATEMONO_TERRACE
									  ,Apm_Config_Search::TATEMONO_TOWN
									  ,Apm_Config_Search::TATEMONO_IKKODATE
									  ,Apm_Config_Search::TATEMONO_KASIYA
									  ,Apm_Config_Search::TATEMONO_NAGAYA);
		}

		$where .= " AND T03.T03_TATEMONO_TYPE_CD in (";
		for($i=0; $i<count($aryTatemonoCd); $i++)
		{
		$db_params['strTatemonoCd_'.$i] = $aryTatemonoCd[$i];
		$where .= " :strTatemonoCd_".$i." ,";
		}
				// 最後のカンマを削除
				$where = substr($where, 0, (strlen($where)-1) );
				$where .= ") ";

		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//駅徒歩
		//
		// ekitoho   : １分以内、５分以内、７分以内、１０分以内、１５分以内、指定なし
		// bas_riyou : バス利用可
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

		//指定した場合
		// 2011/01/13 駅検索時に指定した駅（沿線）からの徒歩分で絞り込むようにする。
		if (!empty($params['ekitoho']))
		{
			$db_params['strEkitoho'] = $params['ekitoho'];

			// 路線検索以外の場合に条件を作成
			// 路線検索の場合は、
			//「/renew/models/BukkenList.php、/mobileapi/models/BukkenList.php」に記載
			// ※パフォーマンス劣化を防ぐため、駅選択時のSQL本体に条件を記載
			if ($params['SrhKbn'] != Apm_Config_Search::SRHKBN_ENSENEKI)
			{
			    $where .= " AND (";
			    $where .= " (";
			    $where .= "          NVL(T03.T03_ENSEN_CD01, '9999') <> '9999' " ;
			    $where .= "      AND NVL(T03.T03_BUS_JYOUSHA, 0) = 0 " ;
			    $where .= "      AND T03.T03_TOHO01 <= :strEkitoho ";
			    $where .= " ) ";
			    $where .= "   OR";
			    $where .= " (";
			    $where .= "          NVL(T03.T03_ENSEN_CD02, '9999') <> '9999' " ;
			    $where .= "      AND NVL(T03.T03_BUS_JYOUSHA02, 0) = 0 " ;
			    $where .= "      AND T03.T03_TOHO02 <= :strEkitoho ";
			    $where .= " ) ";
			    $where .= "   OR";
			    $where .= " (";
			    $where .= "          NVL(T03.T03_ENSEN_CD03, '9999') <> '9999' " ;
			    $where .= "      AND NVL(T03.T03_BUS_JYOUSHA03, 0) = 0 " ;
			    $where .= "      AND T03.T03_TOHO03 <= :strEkitoho ";
			    $where .= " ) ";
			    $where .= ") ";
			}
		}

		// バス利用可
		if (!empty($params['bas_riyou']) && $params['bas_riyou'] == "on")
		{
			$where .= " AND ( T03.T03_BUS_GAISHA IS NOT NULL OR T03.T03_BUS_GAISHA02 IS NOT NULL OR T03.T03_BUS_GAISHA03 IS NOT NULL)";
		}

		//+++++++++++++++++++
		//専有面積
		//
		// senyu1 : 下限
		// senyu2 : 上限
		//+++++++++++++++++++

		if (!empty($params['senyu1']) && !empty($params['senyu2']) )
		{
			if ($params['senyu1'] == "1")
			{
				$params['senyu1'] = 0;
			}
			// 専有面積の下限なし・上限あり
			if ($params['senyu1'] == "0" && $params['senyu2'] <> "99999")
			{
				$db_params['strSenyu2'] = $params['senyu2'];
				$where .= " AND (T03.T03_SENYUU_MENSEKI <= :strSenyu2 ) ";
			}
			// 専有面積の下限あり・上限なし
			elseif ($params['senyu2'] == "99999" && $params['senyu1'] <> "0")
			{
				$db_params['strSenyu1'] = $params['senyu1'];
				$where .= " AND (T03.T03_SENYUU_MENSEKI >= :strSenyu1 ) ";
			}
			// 専有面積の下限あり・上限あり
			else if($params['senyu1'] <> "0" && $params['senyu2'] <> "99999")
			{
				$db_params['strSenyu1'] = $params['senyu1'];
				$db_params['strSenyu2'] = $params['senyu2'];

				$where .= " AND ( T03.T03_SENYUU_MENSEKI BETWEEN :strSenyu1 AND :strSenyu2 ) ";
			}
			if ($params['senyu1'] == "0")
			{
				$params['senyu1'] = 1;
			}
		}

		//+++++++++++++++++++++++++++
		//間取り
		//
		// madori10 : 1R
		// madori11 : 1K
		// madori12 : 1DK,1SDK
		// madori14 : 1LDK,1SLDK
		// madori21 : 2R,2K
		// madori22 : 2DK,2SDK
		// madori24 : 2LDK,2SLDK
		// madori31 : 3R,3K
		// madori32 : 3DK,3SDK
		// madori34 : 3LDK,3SLDK
		// madori41 : 4R,4K
		// madori42 : 4DK,4SDK
		// madori44 : 4LDK,4SLDK
		// madori51 : 5R～7SLDK
		//+++++++++++++++++++++++++++

		if (!empty($params['madori10']) || !empty($params['madori11']) || !empty($params['madori12']) || !empty($params['madori14']) ||
			!empty($params['madori21']) || !empty($params['madori22']) || !empty($params['madori24']) ||
			!empty($params['madori31']) || !empty($params['madori32']) || !empty($params['madori34']) ||
			!empty($params['madori41']) || !empty($params['madori42']) || !empty($params['madori44']) || !empty($params['madori51']) )
		{
			$aryMadoriCd = array();

			//1R
			if (!empty($params['madori10']) && $params['madori10'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_1R);
			}
			//1K
			if (!empty($params['madori11']) && $params['madori11'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_1K);
			}
			//1DK(+S)
			if (!empty($params['madori12']) && $params['madori12'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_1DK, Apm_Config_Search::MADORI_1SDK);
			}
			//1LDK(+S)
			if (!empty($params['madori14']) && $params['madori14'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_1LDK, Apm_Config_Search::MADORI_1SLDK);
			}
			//2K
			if (!empty($params['madori21']) && $params['madori21'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_2R, Apm_Config_Search::MADORI_2K);
			}
			//2DK(+S)
			if (!empty($params['madori22']) && $params['madori22'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_2DK, Apm_Config_Search::MADORI_2SDK);
			}
			//2LDK(+S)
			if (!empty($params['madori24']) && $params['madori24'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_2LDK, Apm_Config_Search::MADORI_2SLDK);
			}
			//3K
			if (!empty($params['madori31']) && $params['madori31'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_3R, Apm_Config_Search::MADORI_3K);
			}
			//3DK(+S)
			if (!empty($params['madori32']) && $params['madori32'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_3DK, Apm_Config_Search::MADORI_3SDK);
			}
			//3LDK
			if (!empty($params['madori34']) && $params['madori34'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_3LDK, Apm_Config_Search::MADORI_3SLDK);
			}
			//4K
			if (!empty($params['madori41']) && $params['madori41'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_4R, Apm_Config_Search::MADORI_4K);
			}
			//4DK(+S)
			if (!empty($params['madori42']) && $params['madori42'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_4DK, Apm_Config_Search::MADORI_4SDK);
			}
			//4LDK
			if (!empty($params['madori44']) && $params['madori44'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_4LDK, Apm_Config_Search::MADORI_4SLDK);
			}
			//5K～
			if (!empty($params['madori51']) && $params['madori51'] == "on")
			{
				array_push($aryMadoriCd, Apm_Config_Search::MADORI_5R
										,Apm_Config_Search::MADORI_5R
										,Apm_Config_Search::MADORI_5K
										,Apm_Config_Search::MADORI_5DK
										,Apm_Config_Search::MADORI_5SDK
										,Apm_Config_Search::MADORI_5LDK
										,Apm_Config_Search::MADORI_5SLDK
										,Apm_Config_Search::MADORI_6R
										,Apm_Config_Search::MADORI_6K
										,Apm_Config_Search::MADORI_6DK
										,Apm_Config_Search::MADORI_6SDK
										,Apm_Config_Search::MADORI_6LDK
										,Apm_Config_Search::MADORI_6SLDK
										,Apm_Config_Search::MADORI_7R
										,Apm_Config_Search::MADORI_7K
										,Apm_Config_Search::MADORI_7DK
										,Apm_Config_Search::MADORI_7SDK
										,Apm_Config_Search::MADORI_7LDK
										,Apm_Config_Search::MADORI_7SLDK);
			}

			$where .= " AND T03.T03_MADORI_CD in (";
			for($i=0; $i<count($aryMadoriCd); $i++)
			{
				$db_params['strMadoriCd_'.$i] = $aryMadoriCd[$i];
				$where .= " :strMadoriCd_".$i." ,";
			}
			// 最後のカンマを削除
			$where = substr($where, 0, (strlen($where)-1) );
			$where .= ") ";
		}

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//築年数
		//
		// built : 新築、3年以内、5年以内、10年以内、指定なし
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

		if (!empty($params['built']))
		{
			if ($params['built'] == "1")
			{
				$where .= " AND T03.T03_SHINCHIKU_FLAG = 1 ";
			}
			elseif ($params['built'] <> "0")
			{
				$db_params['strBuilt1'] = (date(Y) - $params['built']) . date(m);
				$db_params['strBuilt2'] = (date(Y) + 1) . date(m);

				$where .= " AND (";
				$where .= " ( LPAD(T03.T03_KANSEINEN, 4, '0000') || LPAD(T03.T03_KANSEITSUKI, 2, '00') >= :strBuilt1 )";
				$where .= " AND ( LPAD(T03.T03_KANSEINEN, 4, '0000') || LPAD(T03.T03_KANSEITSUKI, 2, '00') < :strBuilt2 ))";
			}
		}
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//情報の新しさ
		//
		// jyohou : 本日更新、3日以内更新、1週間以内更新、指定なし
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

		if (!empty($params['jyohou']) && $params['jyohou'] <> "0" )
		{
			$db_params['strJyohou'] = $params['jyohou'];
			$where .=  " AND ( TO_DATE( TO_CHAR(T03.T03_KOUSHINBI, 'YYYYMMDD') ) > TO_DATE( TO_CHAR( SYSDATE - :strJyohou , 'YYYYMMDD') ) ) ";
		}

		//++++++++
		//画像
		//++++++++
		if (!empty($params['kodawari1']) && $params['kodawari1'] == "on")
		{
			$where .= " AND (   T03_NAISOU_GAZOU01 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU02 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU03 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU04 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU05 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU06 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU07 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU08 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU09 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU10 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON01 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON02 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON03 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON04 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON05 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON06 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON07 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON08 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON09 IS NOT NULL";
			$where .= "      OR T03_NAISOU_GAZOU_COMMON10 IS NOT NULL)";
		}
		if (!empty($params['kodawari2']) && $params['kodawari2'] == "on")
		{
			$where .= " AND (   T03_PANORAMA_GAZOU01 IS NOT NULL";
			$where .= "      OR T03_PANORAMA_GAZOU02 IS NOT NULL";
			$where .= "      OR T03_PANORAMA_GAZOU_COMMON01 IS NOT NULL";
			$where .= "      OR T03_PANORAMA_GAZOU_COMMON02 IS NOT NULL)";
		}

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//PRコメント
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		if (!empty($params['prcomment']) && $params['prcomment'] <> "" )
		{
			$where .= " AND (T03_PR01 like '%".$params['prcomment']."%' or T03_PR02 like '%".$params['prcomment']."%')";
		}

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//キャンペーン  campaign[0]～（配列）
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// UPDATE 2011/09/14 H.Imamura
		// レスポンス改善のため、等結合に変更。distinctで一意にする。
		if(array_key_exists('campaign', $params) && isset($params['campaign']))
		{
			$where .= " AND T03.T03_HEYA_CD = CAM.T03_HEYA_CD";
			$where .= " AND M94.M94_CAMPAIGN_CD = CAM.T03_CAMPAIGN_CD";
			$where .= " AND M94.M94_CAMPAIGN_CD in (";
			// カンマ区切りに変換し、DBパラメータにつめる
			for($i = 0; $i < count($params['campaign']); $i++)
			{
				$db_params['strCampaign_'.$i] = $params['campaign'][$i];
				$where .= " :strCampaign_".$i." ,";
			}
			// 最後のカンマを削除
			$where = substr($where, 0, (strlen($where)-1) );
			$where .= " )";
			$where .= " AND NVL(M94.M94_START_YMD,'99999999') <= TO_CHAR(SYSDATE, 'YYYYMMDD')";
			$where .= " AND NVL(M94.M94_END_YMD,'99999999')   >= TO_CHAR(SYSDATE, 'YYYYMMDD')";
			$where .= " AND M94.M94_DELETE_FLAG = 0";
			// モバイル
			if(array_key_exists('isMobile', $params) == true && $params['isMobile'] == 1)
			{
				$where .= " AND M94.M94_MOBILE_KBN = '1' ";
			}
			// PC
			else
			{
				$where .= " AND M94.M94_MOBILE_KBN = '0' ";
			}
			$where .= " AND (";
			$where .= "   M94.M94_CAMPAIGN_CD <> 11";
			$where .= "   OR EXISTS (";
			$where .= "     SELECT 1";
			$where .= "     FROM M94KADEN KEY";
			$where .= "     WHERE";
			$where .= "       CAM.T03_OTAKARA_CD = KEY.M94_KADEN_CD";
			$where .= "       AND NVL(KEY.M94_INS_DATE, SYSDATE+1) <= SYSDATE";
			$where .= "       AND NVL(KEY.M94_DEL_DATE, SYSDATE)   >= SYSDATE";
			$where .= "   )";
			$where .= " )";
		}

		// 2011/4/12 #351:家電部屋キャンペーン対応 Start
		/*
		 * 家電部屋キャンペーンICON対応の為、常にキャンペーンテーブルを結合する。
		 * キャンペーン終了次第、削除する。
		 * お宝キャンペーンは終了の為、コメントアウト。
		 * 他キャンペーン検索はWhere句へExists対応する。
		 */
/*
		if(array_key_exists('campaign', $params) && isset($params['campaign']))
		{
			// 家電部屋キャンペーンのみかを判定
			$otakara_campaign_only_flg = true;
			// 家電部屋キャンペーンがあるかを判定
			// UPDATE Start 2011/07/11 AKBキャンペーン対応 SS sakakibara-y
			$campaign_flg = array();
			//$kaden_campaign_flg = false;
			foreach( $params['campaign'] as $key => $val )
			{
				if(Apm_Bukkenitems::IsDisplayIconCampaign($val))
				{
					$campaign_flg[$val] = $val;
					//$kaden_campaign_flg = true;
				}
				else
				{
					$otakara_campaign_only_flg = false;
				}
			}

			// 家電部屋キャンペーン以外を含む場合
			if(!$otakara_campaign_only_flg)
			{
				$where .= " AND EXISTS ( SELECT 1 FROM T03WEB_HEYA_CAMPAIGN CAM, M94CAMPAIGN M94 WHERE ";
				$where .= " CAM.T03_CAMPAIGN_CD in ( ";

				// カンマ区切りに変換し、DBパラメータにつめる
				for($i = 0; $i < count($params['campaign']); $i++)
				{
					// お宝キャンペーン以外をWhere句の条件に追加する
					if($params['campaign'][$i] != Apm_Config_Search::KADEN_CAMPAIGN_CD)
					{
						$db_params['strCampaign_'.$i] = $params['campaign'][$i];
						$where .= " :strCampaign_".$i." ,";
					}
				}
				// 最後のカンマを削除
				$where = substr($where, 0, (strlen($where)-1) );
				$where .= " ) ";
				$where .= " AND T03.T03_HEYA_CD = CAM.T03_HEYA_CD";
				$where .= " AND CAM.T03_CAMPAIGN_CD = M94.M94_CAMPAIGN_CD";

				// モバイル
				if(array_key_exists('isMobile', $params) == true && $params['isMobile'] == 1)
				{
					$where .= " AND M94.M94_MOBILE_KBN = '1' ";
				}
				// PC
				else
				{
					$where .= " AND M94.M94_MOBILE_KBN = '0' ";
				}
				$where .= " ) ";
			}
/*
			//お宝キャンペーンのみかを判定
			$otakara_campaign_only_flg = true;
			foreach( $params['campaign'] as $key => $val ){
				if($val == Apm_Config_Search::OTAKARA_CAMPAIGN_CD)
				{
					// キーワード取得
					$OtakaraKeyWord = $this->getOtakaraKeyWord();

					$where .= " AND ( ";
					foreach( $OtakaraKeyWord as $key => $val )
					{
						if($key != 0)
						{
							$where .= " or ";
						}
						$where .= " T03_PR01 like '%".$val['M94_OTAKARA_WORD']."%' or T03_PR02 like '%".$val['M94_OTAKARA_WORD']."%' ";
					}
					$where .= " ) ";
				}
				else
				{
					$otakara_campaign_only_flg = false;
				}
			}

			// お宝キャンペーン以外を含む場合
			if(!$otakara_campaign_only_flg)
			{
				$where .= " AND CAM.T03_CAMPAIGN_CD in ( ";

				// カンマ区切りに変換し、DBパラメータにつめる
				for($i = 0; $i < count($params['campaign']); $i++)
				{
					// お宝キャンペーン以外をWhere句の条件に追加する
					if($params['campaign'][$i] != Apm_Config_Search::OTAKARA_CAMPAIGN_CD)
					{
						$db_params['strCampaign_'.$i] = $params['campaign'][$i];
						$where .= " :strCampaign_".$i." ,";
					}
				}
				// 最後のカンマを削除
				$where = substr($where, 0, (strlen($where)-1) );
				$where .= " ) ";
				$where .= " AND T03.T03_HEYA_CD = CAM.T03_HEYA_CD";
				$where .= " AND CAM.T03_CAMPAIGN_CD = M94.M94_CAMPAIGN_CD";

				// モバイル
				if(array_key_exists('isMobile', $params) == true && $params['isMobile'] == 1)
				{
					$where .= " AND M94.M94_MOBILE_KBN = '1' ";
				}
				// PC
				else
				{
					$where .= " AND M94.M94_MOBILE_KBN = '0' ";
				}
			}
		}
*/

/*
		// 家電部屋キャンペーン条件
		// AKBキャンペーン対応のため、コメントアウト
		if ($iconFlag)
		{
			if (!empty($campaign_flg))
			{
				if(!$otakara_campaign_only_flg)
				{
					$where .= " OR (";
				}
				else{
					$where .= " AND (";
				}
				$where .= "  T03.T03_HEYA_CD = ICON.HEYA_CD AND (";
				foreach( $campaign_flg as $icon_flag ){
					$where .= " ICON.CAMPAIGN_ICON_FLAG_" . $icon_flag . '=' . $icon_flag . ' OR';
				}
				// 最後のORを削除
				$where = substr($where, 0, (strlen($where)-2) );
				$where .= " ) )";
			}
			/*
			if ($kaden_campaign_flg)
			{
				$where .= " AND T03.T03_HEYA_CD = ICON.HEYA_CD";
			}
			* /
			else
			{
				$where .= " AND T03.T03_HEYA_CD = ICON.HEYA_CD(+)";
			}
		}
*/

		// 2011/4/12 #351:家電部屋キャンペーン対応 End
		// UPDATE End 2011/07/11 AKBキャンペーン対応 SS sakakibara-y

		// 2014/05/08 災害時住宅支援サイトリニューアル UPDATE imamura-h Start
		//災害支援住宅
		if (!empty($params['sienJutaku']) && $params['sienJutaku'] == "on")
		{
			$where .= " AND (T03.T03_SAIGAI_YUGU_FLAG = 1 OR T03.T03_SAIGAI_CYUKAI_TESURYO_FLG = 1) ";
			//$where .= " AND (T03.T03_SIEN_JUTAKU_FLAG = 1 OR T03.T03_TEN_SIEN_JUTAKU_FLAG = 1) ";
		}
		// 支援住宅検索条件の廃止
		//if(   (!empty($params['hutuSyakuya1']) && $params['hutuSyakuya1'] == 'on')
		//   or (!empty($params['hutuSyakuya2']) && $params['hutuSyakuya2'] == 'on')
		//   or (!empty($params['teikiSyakuya']) && $params['teikiSyakuya'] == "on")
		//  )
		//{
		//	$where .= " AND ( ";
		//	$saigaiWhere = '';
		//	if (!empty($params['hutuSyakuya1']) && $params['hutuSyakuya1'] == 'on')
		//	{
		//		$saigaiWhere = " NVL(T03.T03_SAIGAI_HUTU_KBN,'0') = '2' ";
		//	}
		//	if (!empty($params['hutuSyakuya2']) && $params['hutuSyakuya2'] == 'on')
		//	{
		//		if($saigaiWhere <> '')
		//		{
		//			$saigaiWhere .= ' or ';
		//		}
		//		$saigaiWhere .= " NVL(T03.T03_SAIGAI_HUTU_KBN,'0') = '3' ";
		//	}
		//	if (!empty($params['teikiSyakuya']) && $params['teikiSyakuya'] == "on")
		//	{
		//		if($saigaiWhere <> '')
		//		{
		//			$saigaiWhere .= ' or ';
		//		}
		//		$saigaiWhere .= " NVL(T03.T03_SAIGAI_TEIKI_FLG,'0') = '1' ";
		//	}
		//	$where .= $saigaiWhere ." ) ";
		//}
		//if (!empty($params['yuguJutaku']) && $params['yuguJutaku'] == "on")
		//{
		//	$where .= " AND (NVL(T03.T03_SAIGAI_YUGU_FLAG,0) = 1) ";
		//}
		// 2014/05/08 災害時住宅支援サイトリニューアル UPDATE imamura-h End

		return $where;
	}

	/**
	 * こだわり条件選択のWhere句を取得
	 *
	 * @access public
	 */
	public function getKodawariWhere($params, &$db_params)
	{
		$where .= "";

		//+++++++++++++
		//こだわり条件
		//+++++++++++++

		//**********************************
		//構造種別
		//
		// kouzou1 : RC造
		// kouzou2 : 鉄筋造
		// kouzou3 : 木造
		// kouzou4 : ブロック・その他
		//**********************************
		if ( !empty($params['kodawari20']) || !empty($params['kodawari21']) || !empty($params['kodawari136'])
		  || !empty($params['kodawari22']) || !empty($params['kodawari23']) || !empty($params['kodawari24']))
		{
			$aryKouzou = array();

			//RC造 (鉄骨造)
			if (!empty($params['kodawari20']) && $params['kodawari20'] == "on")
			{
				array_push($aryKouzou, Apm_Config_Search::KOZO_TEKKOTUZOU);
			}

			//鉄筋造 (鉄筋コンクリート造)
			if (!empty($params['kodawari21']) && $params['kodawari21'] == "on")
			{
				array_push($aryKouzou, Apm_Config_Search::KOZO_RC);
			}

			//SRC(鉄骨鉄筋コンクリート) 2013.03.05 Add(その他から移動)
			if (!empty($params['kodawari136']) && $params['kodawari136'] == "on")
			{
				array_push($aryKouzou, Apm_Config_Search::KOZO_SRC);
			}

			//軽量鉄骨造 (軽量鉄骨造)
			if (!empty($params['kodawari22']) && $params['kodawari22'] == "on")
			{
				array_push($aryKouzou, Apm_Config_Search::KOZO_KEIRYOTEKKOTUZOU);
			}

			//木造 (木造)
			if (!empty($params['kodawari23']) && $params['kodawari23'] == "on")
			{
				array_push($aryKouzou, Apm_Config_Search::KOZO_MOKUZOU);
			}

			//その他 (ALC、PC(プレキャストコンクリート)、鉄筋ブロック、その他、舗装、重量鉄骨造)
			if (!empty($params['kodawari24']) && $params['kodawari24'] == "on")
			{
				array_push($aryKouzou, Apm_Config_Search::KOZO_ALC
									 , Apm_Config_Search::KOZO_PC
									 , Apm_Config_Search::KOZO_TEKKINBLOCK
									 , Apm_Config_Search::KOZO_SONOTA
									 , Apm_Config_Search::KOZO_HOSOU
									 , Apm_Config_Search::KOZO_JYURYOTEKKOTUZOU);
			}

			$where .= " AND T03.T03_TATEMONO_KOUZOU_CD in (";
			for($i=0; $i<count($aryKouzou); $i++)
			{
				$db_params['strKouzou_'.$i] = $aryKouzou[$i];
				$where .= " :strKouzou_".$i." ,";
			}
			// 最後のカンマを削除
			$where = substr($where, 0, (strlen($where)-1) );
			$where .= " ) ";
		}

		//********************************************************************
		//コンセプト
		//********************************************************************
		//リノベーション物件
		if (!empty($params['kodawari116']) && $params['kodawari116'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI84 = 1";
		}
		//リフォーム済み
		if (!empty($params['kodawari117']) && $params['kodawari117'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI85 = 1";
		}
		//日当たり良好
		if (!empty($params['kodawari118']) && $params['kodawari118'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI86 = 1";
		}
		//閑静な住宅街
		if (!empty($params['kodawari119']) && $params['kodawari119'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI87 = 1";
		}
		//タイル貼り
		if (!empty($params['kodawari120']) && $params['kodawari120'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI88 = 1";
		}
		//家具付き
		if (!empty($params['kodawari121']) && $params['kodawari121'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI89 = 1";
		}
		//食器洗い乾燥機
		if (!empty($params['kodawari122']) && $params['kodawari122'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI90 = 1";
		}
		//デザイナーズ
		if (!empty($params['kodawari94']) && $params['kodawari94'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI64 = 1";
		}
		//分譲賃貸
		if (!empty($params['kodawari125']) && $params['kodawari125'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI93 = 1";
		}
		//タワーマンション
		if (!empty($params['kodawari126']) && $params['kodawari126'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI94 = 1";
		}
		//********************************************************************
		//入居条件
		//********************************************************************
		//即入居可
		if (!empty($params['kodawari9']) && $params['kodawari9'] == "on")
		{
			$where .= " AND T03.T03_HEYA_JYOUKYOU = 1";
		}
		//ペット相談可
		if (!empty($params['kodawari10']) && $params['kodawari10'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN01 = 1";
		}
		//楽器相談可
		if (!empty($params['kodawari11']) && $params['kodawari11'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN02 = 1";
		}
		//家賃カード決済可
		if (!empty($params['kodawari18']) && $params['kodawari18'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN09 = 1";
		}
		//連帯保証人不要
		if (!empty($params['kodawari19']) && $params['kodawari19'] == "on")
		{
			$where .= " AND T03.T03_HOSHOUNIN_FLAG = 0";
		}
		//女性限定
		if (!empty($params['kodawari15']) && $params['kodawari15'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN06 = 1";
		}
		//事務所可
		if (!empty($params['kodawari12']) && $params['kodawari12'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN03 = 1";
		}
		//ルームシェア可
		if (!empty($params['kodawari132']) && $params['kodawari132'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN10 = 1";
		}
		//二人入居可
		if (!empty($params['kodawari134']) && $params['kodawari134'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN12 = 1";
		}
		//高齢者向け
		if (!empty($params['kodawari14']) && $params['kodawari14'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN07 = 1";
		}
		//特定優良賃貸住宅
		if (!empty($params['kodawari133']) && $params['kodawari133'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN11 = 1";
		}
		//マンスリー可
		if (!empty($params['kodawari135']) && $params['kodawari135'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN13 = 1";
		}
		//********************************************************************
		//建物設備
		//********************************************************************
		//エレベータ
		if (!empty($params['kodawari31']) && $params['kodawari31'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI01 = 1";
		}
		//バリアフリー
		if (!empty($params['kodawari95']) && $params['kodawari95'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI65 = 1";
		}
		//ゴミ集積場
		if (!empty($params['kodawari36']) && $params['kodawari36'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI06 = 1";
		}
		//宅配ボックス
		if (!empty($params['kodawari32']) && $params['kodawari32'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI02 = 1";
		}
		//オール電化
		if (!empty($params['kodawari93']) && $params['kodawari93'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI63 = 1";
		}
		//都市ガス
		if (!empty($params['kodawari130']) && $params['kodawari130'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI98 = 1";
		}
		//プロパンガス
		if (!empty($params['kodawari131']) && $params['kodawari131'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI99 = 1";
		}
		//********************************************************************
		//テレビ・通信
		//********************************************************************
		//CATV
		if (!empty($params['kodawari55']) && $params['kodawari55'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI25 = 1";
		}
		//CSアンテナ
		if (!empty($params['kodawari54']) && $params['kodawari54'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI24 = 1";
		}
		//BSアンテナ
		if (!empty($params['kodawari53']) && $params['kodawari53'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI23 = 1";
		}
		//インターネット対応
		if (!empty($params['kodawari97']) && $params['kodawari97'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI67 = 1";
		}
		//地デジ対応
		if (!empty($params['kodawari104']) && $params['kodawari104'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI74 = 1";
		}
		//地デジ対応TV付
		if (!empty($params['kodawari103']) && $params['kodawari103'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI73 = 1";
		}
		//有線放送
		if (!empty($params['kodawari56']) && $params['kodawari56'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI26 = 1";
		}
		//光ファイバー
		if (!empty($params['kodawari98']) && $params['kodawari98'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI68 = 1";
		}
		//インターネット月額利用料込み
		if (!empty($params['kodawari111']) && $params['kodawari111'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI81 = 1";
		}
		//********************************************************************
		//セキュリティ
		//********************************************************************
		//TVインターフォン
		if (!empty($params['kodawari75']) && $params['kodawari75'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI45 = 1";
		}
		//オートロック
		if (!empty($params['kodawari33']) && $params['kodawari33'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI03 = 1";
		}
		//防犯カメラ
		if (!empty($params['kodawari107']) && $params['kodawari107'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI77 = 1";
		}
		//24時間緊急対応
		if (!empty($params['kodawari34']) && $params['kodawari34'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI04 = 1";
		}
		//管理人あり
		if (!empty($params['kodawari123']) && $params['kodawari123'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI91 = 1";
		}
		//ディンプルキー
		if (!empty($params['kodawari124']) && $params['kodawari124'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI92 = 1";
		}
		//********************************************************************
		//部屋環境
		//********************************************************************
		//フローリング
		if (!empty($params['kodawari61']) && $params['kodawari61'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI31 = 1";
		}
		//ロフト
		if (!empty($params['kodawari62']) && $params['kodawari62'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI32 = 1";
		}
		//メゾネット
		if (!empty($params['kodawari77']) && $params['kodawari77'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI47 = 1";
		}
		//エアコン
		if (!empty($params['kodawari46']) && $params['kodawari46'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI16 = 1";
		}
		//1階
		if (!empty($params['kodawari4']) && $params['kodawari4'] == "on")
		{
			$where .= " AND T03.T03_KAI = '1'";
		}
		//2階以上
		if (!empty($params['kodawari5']) && $params['kodawari5'] == "on")
		{
			$where .= " AND T03.T03_KAI >= '2'";
		}
		//角部屋
		if (!empty($params['kodawari101']) && $params['kodawari101'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI71 = 1";
		}
		//専用庭
		if (!empty($params['kodawari73']) && $params['kodawari73'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI43 = 1";
		}
		//バルコニー・ベランダ
		if (!empty($params['kodawari112']) && $params['kodawari112'] == "on")
		{
			$where .= " AND (T03.T03_SETSUBI34 = 1 OR T03.T03_SETSUBI62 = 1)";
		}
		//出窓
		if (!empty($params['kodawari66']) && $params['kodawari66'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI36 = 1";
		}
		//南向き
		if (!empty($params['kodawari8']) && $params['kodawari8'] == "on")
		{
			$where .= " AND T03.T03_HOUGAKU = 3";
		}
		//床暖房
		if (!empty($params['kodawari87']) && $params['kodawari87'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI57 = 1";
		}
		//ルーフバルコニー
		if (!empty($params['kodawari127']) && $params['kodawari127'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI95 = 1";
		}
		//バルコニー2面以上
		if (!empty($params['kodawari128']) && $params['kodawari128'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI96 = 1";
		}
		//24時間換気システム
		if (!empty($params['kodawari129']) && $params['kodawari129'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI97 = 1";
		}
		//********************************************************************
		//キッチン
		//********************************************************************
		//システムキッチン
		if (!empty($params['kodawari59']) && $params['kodawari59'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI29 = 1";
		}
		//ガスキッチン
		if (!empty($params['kodawari60']) && $params['kodawari60'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI30 = 1";
		}
		//ＩＨクッキングヒータ
		if (!empty($params['kodawari78']) && $params['kodawari78'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI48 = 1";
		}
		//コンロ2口以上
		if (!empty($params['kodawari114']) && $params['kodawari114'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI82 = 1";
		}
		//対面キッチン(カウンターキッチン)
		if (!empty($params['kodawari79']) && $params['kodawari79'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI49 = 1";
		}
		//冷蔵庫あり
		if (!empty($params['kodawari67']) && $params['kodawari67'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI37 = 1";
		}
		//ディスポーザー
		if (!empty($params['kodawari80']) && $params['kodawari80'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI50 = 1";
		}
		//********************************************************************
		//バス・トイレ
		//********************************************************************
		//バス・トイレ別
		if (!empty($params['kodawari65']) && $params['kodawari65'] == "on")
		{
			$where .= " AND (T03.T03_SETSUBI13 = 1 OR T03.T03_SETSUBI35 = 1)";
		}
		//室内洗濯機置き場
		if (!empty($params['kodawari63']) && $params['kodawari63'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI33 = 1";
		}
		//独立洗面台
		if (!empty($params['kodawari83']) && $params['kodawari83'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI53 = 1";
		}
		//シャンプードレッサ
		if (!empty($params['kodawari45']) && $params['kodawari45'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI15 = 1";
		}
		//給湯
		if (!empty($params['kodawari113']) && $params['kodawari113'] == "on")
		{
			$where .= " AND (T03.T03_SETSUBI10 = 1 OR T03.T03_SETSUBI11 = 1)";
		}
		//追い焚き
		if (!empty($params['kodawari44']) && $params['kodawari44'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI14 = 1";
		}
		//温水洗浄暖房便座
		if (!empty($params['kodawari86']) && $params['kodawari86'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI56 = 1";
		}
		//浴室換気乾燥機
		if (!empty($params['kodawari81']) && $params['kodawari81'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI51 = 1";
		}
		//********************************************************************
		//収納
		//********************************************************************
		//トランクルーム
		if (!empty($params['kodawari91']) && $params['kodawari91'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI61 = 1";
		}
		//床下収納
		if (!empty($params['kodawari68']) && $params['kodawari68'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI38 = 1";
		}
		//シューズボックス
		if (!empty($params['kodawari115']) && $params['kodawari115'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI83 = 1";
		}
		//クローゼット
		if (!empty($params['kodawari70']) && $params['kodawari70'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI40 = 1";
		}
		//ウォークインクローゼット
		if (!empty($params['kodawari90']) && $params['kodawari90'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI60 = 1";
		}
		//********************************************************************
		//室外設備
		//********************************************************************
		//駐車場
		if (!empty($params['kodawari7']) && $params['kodawari7'] == "on")
		{
			$where .= " AND (T03.T03_CHUUSHAJYOU_KUBUN = 1 OR T03.T03_CHUUSHAJYOU_KUBUN = 2)";
		}
		//駐輪場
		if (!empty($params['kodawari38']) && $params['kodawari38'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI08 = 1";
		}
		//バイク置き場
		if (!empty($params['kodawari39']) && $params['kodawari39'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI09 = 1";
		}
		//********************************************************************
		//(非表示項目）
		//********************************************************************
		//-------2010/12/1リニューアル時使用しない項目------
		//子供可
		if (!empty($params['kodawari13']) && $params['kodawari13'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN04 = 1";
		}
		//法人限定
		if (!empty($params['kodawari16']) && $params['kodawari16'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN05 = 1";
		}
		//単身者不可
		if (!empty($params['kodawari17']) && $params['kodawari17'] == "on")
		{
			$where .= " AND T03.T03_NYUUKYO_JYOUKEN08 = 1";
		}
		//集会場
		if (!empty($params['kodawari35']) && $params['kodawari35'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI05 = 1";
		}
		//コンクリート打ちっぱなし（外観）
		if (!empty($params['kodawari37']) && $params['kodawari37'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI07 = 1";
		}
		//シャワー
		if (!empty($params['kodawari42']) && $params['kodawari42'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI12 = 1";
		}
		//冷房
		if (!empty($params['kodawari47']) && $params['kodawari47'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI17 = 1";
		}
		//暖房
		if (!empty($params['kodawari48']) && $params['kodawari48'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI18 = 1";
		}
		//ガスファンヒーター
		if (!empty($params['kodawari49']) && $params['kodawari49'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI19 = 1";
		}
		//灯油ファンヒーター
		if (!empty($params['kodawari50']) && $params['kodawari50'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI20 = 1";
		}
		//灯油ボイラー
		if (!empty($params['kodawari51']) && $params['kodawari51'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI21 = 1";
		}
		//セントラルヒーティング
		if (!empty($params['kodawari52']) && $params['kodawari52'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI22 = 1";
		}
		//屋内駐車場
		if (!empty($params['kodawari57']) && $params['kodawari57'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI27 = 1";
		}
		//駐車場ロードヒーティング
		if (!empty($params['kodawari58']) && $params['kodawari58'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI28 = 1";
		}
		//インターホン
		if (!empty($params['kodawari69']) && $params['kodawari69'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI39 = 1";
		}
		//押入
		if (!empty($params['kodawari71']) && $params['kodawari71'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI41 = 1";
		}
		//電気コンロ
		if (!empty($params['kodawari72']) && $params['kodawari72'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI42 = 1";
		}
		//コンクリート打ちっぱなし（内装）
		if (!empty($params['kodawari74']) && $params['kodawari74'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI44 = 1";
		}
		//共用庭
		if (!empty($params['kodawari76']) && $params['kodawari76'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI46 = 1";
		}
		//浴室TV
		if (!empty($params['kodawari82']) && $params['kodawari82'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI52 = 1";
		}
		//郵便受け
		if (!empty($params['kodawari84']) && $params['kodawari84'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI54 = 1";
		}
		//暖房便座
		if (!empty($params['kodawari85']) && $params['kodawari85'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI55 = 1";
		}
		//ベッド
		if (!empty($params['kodawari88']) && $params['kodawari88'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI58 = 1";
		}
		//照明器具
		if (!empty($params['kodawari89']) && $params['kodawari89'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI59 = 1";
		}
		//サンルーム
		if (!empty($params['kodawari96']) && $params['kodawari96'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI66 = 1";
		}
		//駐車場2台可
		if (!empty($params['kodawari99']) && $params['kodawari99'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI69 = 1";
		}
		//自走式駐車場
		if (!empty($params['kodawari100']) && $params['kodawari100'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI70 = 1";
		}
		//ガスコンロ設置可
		if (!empty($params['kodawari102']) && $params['kodawari102'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI72 = 1";
		}
		//二重サッシ
		if (!empty($params['kodawari105']) && $params['kodawari105'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI75 = 1";
		}
		//ペアガラス
		if (!empty($params['kodawari106']) && $params['kodawari106'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI76 = 1";
		}
		//物置
		if (!empty($params['kodawari108']) && $params['kodawari108'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI78 = 1";
		}
		//防犯ガラス
		if (!empty($params['kodawari109']) && $params['kodawari109'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI79 = 1";
		}
		//バス１坪以上
		if (!empty($params['kodawari110']) && $params['kodawari110'] == "on")
		{
			$where .= " AND T03.T03_SETSUBI80 = 1";
		}

		//人気こだわり

		if (!empty($params['kodawari_01']) && $params['kodawari_01'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_01_JYOSEI_FLG = 1";
		}
		if (!empty($params['kodawari_02']) && $params['kodawari_02'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_02_KOSODATE_FLG = 1";
		}
		if (!empty($params['kodawari_03']) && $params['kodawari_03'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_03_RYORI_FLG = 1";
		}
		if (!empty($params['kodawari_04']) && $params['kodawari_04'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_04_PET_FLG = 1";
		}
		if (!empty($params['kodawari_05']) && $params['kodawari_05'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_05_SHUNO_FLG = 1";
		}
		if (!empty($params['kodawari_06']) && $params['kodawari_06'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_06_SHARE_FLG = 1";
		}
		if (!empty($params['kodawari_07']) && $params['kodawari_07'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_07_RENO_FLG = 1";
		}
		if (!empty($params['kodawari_08']) && $params['kodawari_08'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_08_FUYU_FLG = 1";
		}
		if (!empty($params['kodawari_09']) && $params['kodawari_09'] == "on")
		{
		    $where .= " AND T03.T03_KODAWARI_09_KOUREI_FLG = 1";
		}

		//人気こだわり

		return $where;
	}

	/**
	 * OrderBy句を取得
	 *
	 * @access public
	 * @param  array
	 * @param  array ※参照渡し
	 * @return string
	 */
	public function getOrderBy($params, &$db_params)
	{

		$sql  = ' order by';
		$sql .= ' '.$params['SORT_COLUMN'];
		$sql .= ' '.$params['SORT_ORDER'];

		// 通勤通学時間検索の場合は、所要時間時間でソート
		if($params['SrhKbn'] == Apm_Config_Search::SRHKBN_TUKINTUGAKU)
		{
			$sql .= ' ,T94_TARGET_EKI_TIME';
			$sql .= '  DESC';
		}

		// 2010/12/24 更新日追加
		//$sql .= " , SUBSTR(TO_CHAR(T03_KOUSHINBI, 'yyyymmddhh24mi'),0,11) ";
		$sql .= " , TO_CHAR(T03_TOUROKUBI, 'yyyymmdd') DESC ";

		return $sql;
	}

	/**
	 * OrderBy句を取得（店舗から一覧)
	 *
	 * @access public
	 * @return string
	 */
	public function getOrderByForShop($params)
	{
		// ランダムでソートキーを変更する
		// shopsortItemはrstobi.jsでランダム生成


		/*

		$sql  = ' order by';

		if($params['shopsortItem'] == '1')
		{
			$sql .= ' M05_TENPO_BANGOU ASC ';
		}
		else if($params['shopsortItem'] == '2')
		{
			$sql .= ' M05_TENPO_BANGOU DESC ';
		}
		else if($params['shopsortItem'] == '3')
		{
			$sql .= ' M05_TENPO_CD ASC ';
		}
		else if($params['shopsortItem'] == '4')
		{
			$sql .= ' M05_TENPO_CD DESC ';
		}
		else if($params['shopsortItem'] == '5')
		{
			$sql .= ' M05_TENPO_NAME ASC ';
		}
		else
		{
			$sql .= ' M05_TENPO_NAME DESC ';
		}

		*/

		$sql = '';


		return $sql;
	}

    /**
     * 社宅控除率取得
     *
	 * @access	public
	 * @param   array
	 * @param	array ※参照渡し
	 * @return  string
     */
	public function getShatakuKoujyoritsu($params)
	{
		$db_param_syataku['strComId'] = $params['ComId'];

		// 社宅控除率取得SQL作成
		$sql  = ' select';
		$sql .= "     M86.M86_COMPANY_NAME";
		$sql .= "    ,M86.M86_SHATAKU_KOUJYORITSU";
		$sql .= "    ,M86.M86_GENRU_FLAG";
		$sql .= ' from';
		$sql .= '     M86SHATAKU_TEIKEI_COMPANY M86';
		$sql .= ' where';
		$sql .= '     M86.M86_COMPANY_CD = :strComId';

		// SQLを実行
		$syataku = $this->dbGetList($sql, $db_param_syataku);

		// 社宅控除率を返却
		return $syataku[0]['M86_SHATAKU_KOUJYORITSU'];
	}

	/**
	 * キャンペーンで絞り込む場合のFROM句取得
	 *
	 * @access public
	 */
	public function getCampFrom($params)
	{
		$strFrom = '';

		/*
		 * UPDATE 2011/09/14 H.Imamura
		 * レスポンス改善のため、キャンペーン条件がある時のみテーブル結合を行う。
		 * ICON表示はSELECT句へ直接記入する方式
		 */
		if(array_key_exists('campaign', $params) && isset($params['campaign']))
		{
			$strFrom  = ' ,T03WEB_HEYA_CAMPAIGN CAM';
			$strFrom .= ' ,M94CAMPAIGN M94';
		}
		return $strFrom;

		/*
		 * 家電部屋キャンペーンICON対応の為、常にキャンペーンテーブルを結合する。
		 * キャンペーン終了次第、削除する。
		 * キャンペーン検索はWhere句へExists対応するため、元のFrom句も不要。
		 */
		// UPDATE Start 2011/06/30 AKBキャンペーン対応 SS sakakibara-y
		/*
		$strFrom .= ' ,(';
		$strFrom .= '   SELECT distinct';
		$strFrom .= '      CAM.T03_CAMPAIGN_CD AS CAMPAIGN_ICON_FLAG';
		$strFrom .= '    , CAM.T03_HEYA_CD AS HEYA_CD';
		$strFrom .= '     FROM';
		$strFrom .= '      M94CAMPAIGN M94';
		$strFrom .= '    , T03WEB_HEYA_CAMPAIGN CAM';
		$strFrom .= '    WHERE';
		$strFrom .= '        M94.M94_CAMPAIGN_CD = CAM.T03_CAMPAIGN_CD';
		$strFrom .= '    AND M94.M94_CAMPAIGN_CD = ' . Apm_Config_Search::KADEN_CAMPAIGN_CD;
		$strFrom .= "    AND NVL(M94.M94_START_YMD,'99999999') <= TO_CHAR(SYSDATE, 'YYYYMMDD')";
		$strFrom .= "    AND NVL(M94.M94_END_YMD,'99999999')   >= TO_CHAR(SYSDATE, 'YYYYMMDD')";
		// 家電の有効期間チェック
		$strFrom .= "    AND EXISTS (";
		$strFrom .= "            SELECT 1 FROM M94KADEN KEY";
		$strFrom .= "             WHERE";
		$strFrom .= "                 CAM.T03_OTAKARA_CD = KEY.M94_KADEN_CD";
		$strFrom .= "             AND NVL(KEY.M94_INS_DATE, SYSDATE+1) <= SYSDATE";
		$strFrom .= "             AND NVL(KEY.M94_DEL_DATE, SYSDATE)   >= SYSDATE";
		$strFrom .= "        )";
		$strFrom .= '    AND M94.M94_DELETE_FLAG = 0';
		// モバイル
		if(array_key_exists('isMobile', $params) == true && $params['isMobile'] == 1)
		{
			$strFrom .= " AND M94.M94_MOBILE_KBN = '1' ";
		}
		// PC
		else
		{
			$strFrom .= " AND M94.M94_MOBILE_KBN = '0' ";
		}
		$strFrom .= ' ) ICON';
		*/
		/*
		$strFrom .= ' ,(';
		$strFrom .= '   SELECT ';
		$strFrom .= '    CAM.T03_HEYA_CD AS HEYA_CD';
		foreach(Apm_Config_Search::$DISPLAY_ICON_CAMPAIGN_CD as $campaign_cd){
		$strFrom .= '    , MAX(CAMPAIGN_ICON_FLAG_' . $campaign_cd . '.ICON_FLAG) AS CAMPAIGN_ICON_FLAG_' . $campaign_cd;
		}
		$strFrom .= '     FROM';
		$strFrom .= '    	T03WEB_HEYA_CAMPAIGN CAM,';
		$strFrom .= '      	M94CAMPAIGN M94,';
		foreach(Apm_Config_Search::$DISPLAY_ICON_CAMPAIGN_CD as $campaign_cd){
		$strFrom .= '     	( SELECT';
		$strFrom .= '    		CAM.T03_HEYA_CD HEYA_CD';
		$strFrom .= '    		,CAM.T03_CAMPAIGN_CD ICON_FLAG';
		$strFrom .= '    		FROM';
		$strFrom .= '      			M94CAMPAIGN M94';
		$strFrom .= '    			, T03WEB_HEYA_CAMPAIGN CAM';
		$strFrom .= '    		WHERE';
		$strFrom .= '        		M94.M94_CAMPAIGN_CD = CAM.T03_CAMPAIGN_CD';
		$strFrom .= '        		AND M94.M94_CAMPAIGN_CD = ' . $campaign_cd;;
		$strFrom .= "    	 		AND NVL(M94.M94_START_YMD,'99999999') <= TO_CHAR(SYSDATE, 'YYYYMMDD')";
		$strFrom .= "    	 		AND NVL(M94.M94_END_YMD,'99999999')   >= TO_CHAR(SYSDATE, 'YYYYMMDD')";
		$strFrom .= '    	 		AND M94.M94_DELETE_FLAG = 0';
		if($campaign_cd == Apm_Config_Search::KADEN_CAMPAIGN_CD){
		// 家電の有効期間チェック
		$strFrom .= "  				AND EXISTS (";
		$strFrom .= "           		SELECT 1 FROM M94KADEN KEY";
		$strFrom .= "             		WHERE";
		$strFrom .= "               		CAM.T03_OTAKARA_CD = KEY.M94_KADEN_CD";
		$strFrom .= "             		AND NVL(KEY.M94_INS_DATE, SYSDATE+1) <= SYSDATE";
		$strFrom .= "             		AND NVL(KEY.M94_DEL_DATE, SYSDATE)   >= SYSDATE";
		$strFrom .= "        		)";
		}else{
//		$strFrom .= "  				AND EXISTS (";
//		$strFrom .= "           		SELECT 1 FROM M94CAMPAIGN_ITEM KEY";
//		$strFrom .= "             		WHERE";
//		$strFrom .= "               		CAM.T03_OTAKARA_CD = KEY.M94_ITEM_CD";
//		$strFrom .= "             		AND KEY.M94_DELETE_FLAG = '0'";
//		$strFrom .= "        		)";
		}
		$strFrom .= '     	) CAMPAIGN_ICON_FLAG_' . $campaign_cd . ',';
		}
		// 最後のカンマを削除
		$strFrom = substr($strFrom, 0, (strlen($strFrom)-1) );
		$strFrom .= '    WHERE';
		$strFrom .= '     M94.M94_CAMPAIGN_CD = CAM.T03_CAMPAIGN_CD';
		foreach(Apm_Config_Search::$DISPLAY_ICON_CAMPAIGN_CD as $campaign_cd){
		$strFrom .= ' AND CAM.T03_HEYA_CD = CAMPAIGN_ICON_FLAG_' . $campaign_cd . '.HEYA_CD(+)';
		}
     	// UPDATE End 2011/06/30 AKBキャンペーン対応 SS sakakibara-y
		// モバイル
		if(array_key_exists('isMobile', $params) == true && $params['isMobile'] == 1)
		{
			$strFrom .= " AND M94.M94_MOBILE_KBN = '1' ";
		}
		// PC
		else
		{
			$strFrom .= " AND M94.M94_MOBILE_KBN = '0' ";
		}
		$strFrom .= ' GROUP BY CAM.T03_HEYA_CD';
		$strFrom .= ' ) ICON';

/*
		// キャンペーン情報が渡された場合
		if(array_key_exists('campaign', $params) && isset($params['campaign']))
		{
			$strFrom = '';

			//お宝キャンペーンのみかを判定
			$otakara_campaign_only_flg = true;
			foreach( $params['campaign'] as $key => $val )
			{
				if($val != Apm_Config_Search::OTAKARA_CAMPAIGN_CD){
					$otakara_campaign_only_flg = false;
					break;
				}
			}

			// お宝キャンペーン以外のキャンペーンがある場合は、キャンペーンテーブルを結合
			if(!$otakara_campaign_only_flg)
			{
				$strFrom  = ' ,T03WEB_HEYA_CAMPAIGN CAM';
				$strFrom .= ' ,M94CAMPAIGN M94';
			}
		}
		return $strFrom;
*/
	}

    /**
     * OEM判定
     */
    public function isOem($params)
    {
    	return ((array_key_exists('OemCd', $params) == true) && (is_null($params['OemCd']) == false) );
    }

    /**
     * お宝キーワード取得判定
     *
     * @access public
     *
     * return array
     */
    public function getOtakaraKeyWord()
    {
    	$db_param = array();

    	$sql  = ' select distinct';
    	$sql .= '     M94_OTAKARA_WORD';
    	$sql .= ' from';
    	$sql .= '     M94CAMPAIGN_OTAKARA_KEYWORD';
    	$sql .= ' where';
    	$sql .= '     M94_DELETE_FLAG = 0';

    	return $this->dbGetList($sql, $db_param);
    }

	/**
     * 加盟店HP作成契約情報取得
     *
     * @access public
     *
     * return array
     */
    public function getHpKeiyakuJoho($params)
    {
    	$db_param['keiyaku_cd'] = $params['keiyaku_cd'];

    	$sql = "";
		$sql .=" SELECT";
		$sql .="         T73_KEIYAKU_CD";
		$sql .="         ,T73_OSUSUME_USE_FLAG";
		$sql .="         ,T73_TENPO_CD";
		$sql .="         ,T73_HOUZIN_CD";
		$sql .="         ,T73_TENPO_CD";
		$sql .="         ,T73_HOUZINMEI";
		$sql .="         ,T73_TENPOMEI";
		$sql .="         ,T73_AREAMEI";
		$sql .="         ,T73_CHOSAKUKEN";
		$sql .="         ,T73_MOUSHIKOMI_KUBUN";
		$sql .="         ,T73_DESIGN_KUBUN";
		$sql .="         ,T73_COLOR_KUBUN";
		$sql .="         ,T73_CHOSAKUKEN";
		$sql .="         ,CASE";
		$sql .="             WHEN T73_TENPOMEI IS NULL THEN T73_HOUZINMEI";
		$sql .="             ELSE T73_TENPOMEI";
		$sql .="          END AS T73_TITLE";
		$sql .="         ,T75_URL";
		$sql .="         ,T75_KENSAKU_URL";
		$sql .="     FROM";
		$sql .="         T73TENPO_HP_KEIYAKU";
		$sql .="         ,T75RENTAL_SERVER_KEIYAKU";
		$sql .="     WHERE";
		$sql .="         T73_KEIYAKU_CD = : keiyaku_cd ";
		$sql .="         AND T73_KEIYAKU_CD = T75_KEIYAKU_CD(+)";
		$sql .="         AND T73_OSUSUME_USE_FLAG = 1";

    	return $this->dbGetData($sql, $db_param);
    }

	/**
	 * 緯度経度のWhere句を取得
	 *
	 * @access public
	 */
	public function getLatLngWhere($params ,&$db_params)
	{
		$where = "";
		if (isset($params['lat1']) && isset($params['lng1'])
				&& isset($params['lat3']) && isset($params['lng3'])) {
			$where = " AND TO_NUMBER(T03.T03_KEIDO) >= :lng1 AND TO_NUMBER(T03.T03_IDO) <= :lat1 AND TO_NUMBER(T03.T03_KEIDO) <= :lng3 AND TO_NUMBER(T03.T03_IDO) >= :lat3 ";
			$db_params['lat1'] = $params['lat1'];
			$db_params['lng1'] = $params['lng1'];
			$db_params['lat3'] = $params['lat3'];
			$db_params['lng3'] = $params['lng3'];
			//$where = " AND sdo_within_distance (POINT(T03.T03_KEIDO T03.T03_IDO), GeomFromText('POINT({$params['lng']} {$params['lat']})'), 'distance = 100') = 'TRUE' ";
		}
		return $where;
	}

	/**
	 * 緯度経度のWhere句を取得
	 *
	 * @access public
	 */
	public function getExcludeDaihyoTatemonoCdWhere($daihyoTatemonoCds ,&$db_params)
	{
		if ($daihyoTatemonoCds == null) {
			return '';
		}
		if (!is_array($daihyoTatemonoCds)) {
			$daihyoTatemonoCds = array($daihyoTatemonoCds);
		}

		$p = '';
		foreach ($daihyoTatemonoCds as $key => $cd) {
			if ($p !== '') {
				$p .= ',';
			}
			$p .= ':daihyoTatemonoCd_' . $key;
			$db_params['daihyoTatemonoCd_' . $key] = $cd;
		}
		return ' AND T03.T03_DAIHYO_TATEMONO_CD NOT IN (' . $p . ' ) ';
	}
	/**
	 * 代表建物コードのWhere句を取得
	 *
	 * @access public
	 */
	public function getDaihyoTatemonoCdWhere($daihyoTatemonoCd, &$db_params)
	{
		if ($daihyoTatemonoCd == null) {
			return '';
		}

		if (is_array($daihyoTatemonoCd)) {
			$p = '';
			foreach ($daihyoTatemonoCd as $key => $cd) {
				if ($p !== '') {
					$p .= ',';
				}
				$p .= ':daihyoTatemonoCd_' . $key;
				$db_params['daihyoTatemonoCd_' . $key] = $cd;
			}
			return ' AND T03.T03_DAIHYO_TATEMONO_CD IN (' . $p . ' ) ';
		} else {
			$db_params['daihyoTatemonoCd'] = $daihyoTatemonoCd;
			return ' AND T03.T03_DAIHYO_TATEMONO_CD = :daihyoTatemonoCd ';
		}
	}

    /**
     * 駅徒歩が指定された場合の条件SQLを取得(駅検索用)
     *
     * @param unknown $db_params
     * @return string
     */
    public static function getEkitohoEkiCondition($db_params)
    {
        $sql = "";

        // 駅徒歩が選択されている場合
        if (!empty($db_params[':strEkitoho']))
        {
            $sql .= "
                AND (
                       (M03.M03_EKI_CD = T03.T03_EKI_CD01 AND NVL(T03.T03_BUS_JYOUSHA, 0) = 0 AND T03.T03_TOHO01 <= :strEkitoho)
                    OR (M03.M03_EKI_CD = T03.T03_EKI_CD02 AND NVL(T03.T03_BUS_JYOUSHA02, 0) = 0 AND T03.T03_TOHO02 <= :strEkitoho)
                    OR (M03.M03_EKI_CD = T03.T03_EKI_CD03 AND NVL(T03.T03_BUS_JYOUSHA03, 0) = 0 AND T03.T03_TOHO03 <= :strEkitoho)
                ) ";
        }
        else
        {
            $sql .= "
                AND (
                       M03.M03_EKI_CD = T03.T03_EKI_CD01
                    OR M03.M03_EKI_CD = T03.T03_EKI_CD02
                    OR M03.M03_EKI_CD = T03.T03_EKI_CD03
                ) ";
        }

        return $sql;
    }
}
?>
